package com.bwei.like.mostitemnews;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.bwei.like.mostitemnews.fragmentFactory.FragmentFactory;
import com.bwei.like.mostitemnews.view.ViewPageIndictor;

public class MainActivity extends AppCompatActivity {

    private ViewPageIndictor viewPageIndictor;
    private LinearLayout linearLayout;
    private ViewPager viewPager;
    private String[] titles = {"视频","军事","国际","以后"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }

    private void initView() {
        viewPageIndictor = (ViewPageIndictor) findViewById(R.id.viewPagerIndictor);
        viewPager = (ViewPager) findViewById(R.id.viewPager);

        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return FragmentFactory.getFragment(titles[position]);
            }

            @Override
            public int getCount() {
                return titles.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        });

        viewPageIndictor.setIndictor(viewPager);
    }
}
